package com.wxh.swagger3.controller;

import com.wxh.swagger3.model.Person;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: PersonController
 * @Description: 个人控制器
 * @Author wxh
 * @Date: 2020/7/17 10:23
 * @Version V1.0.0
 * @Since 1.8
 */
@RestController
@RequestMapping(value = "/person")
@Api(tags = "个人管理")
public class PersonController {

    /*
     *  springboot2.x集成swagger3.0.0步骤
     *  1。 pom.xml 引用 swagger3.0.0
     *  2. 在controller类添加注解@Api、@ApiOperation等
     *  3. springboot启动类添加注解@EnableOpenApi
     *  4. 测试地址：http://ip:port/swagger-ui/index.html
     *
     *  swagger3.0.0这次更新，移除了原来默认的swagger页面路径：http://host/context-path/swagger-ui.html，
     *  新增了两个可访问路径：http://host/context-path/swagger-ui/index.html
     *  和http://host/context-path/swagger-ui/通过调整日志级别，
     *  还可以看到新版本的swagger文档接口也有新增，除了以前老版本的文档接口/v2/api-docs之外，
     *  还多了一个新版本的/v3/api-docs接口。
     *
     */

    @ApiOperation(value = "新增个人信息")
    @PostMapping(value = "/insertPerson")
    public Person insertPerson(@RequestBody Person person){
        return person;
    }

    @ApiOperation(value = "查询个人详情")
    @GetMapping(value = "/getPerson/{id}")
    public Person getPerson(@PathVariable("id") Long id){
        return new Person(1L,"aaa", 21, "上海", "aaa@bbb.com");
    }

    @ApiOperation(value = "查询个人列表")
    @GetMapping(value = "listPerson")
    public List<Person> listPerson(@ApiParam("查看第几页") @RequestParam int pageIndex,
                          @ApiParam("每页多少条") @RequestParam int pageSize) {
        List<Person> result = new ArrayList<>();
        result.add(new Person(2L,"bbb", 50, "北京", "aaa@ccc.com"));
        result.add(new Person(3L,"ccc", 21, "广州", "aaa@ddd.com"));
        return result;
    }

    @ApiOperation(value = "删除个人信息")
    @DeleteMapping("/deletePerson/{id}")
    public String deletePerson(@PathVariable Long id) {
        return "delete person : " + id;
    }
}
